using System;
using System.Collections.Generic;
using System.Threading;
using System.Diagnostics;
using Dff;


namespace SwModem.Com
{
    /// <summary>
    /// Represents a comunication channel. Its characteristics are selectable and passed as a 
    /// parameter when invoking the constructor of the class
    /// </summary>
    [Serializable]
    public class Channel 
    {
    //    private int          _grain;
    //    private Port<double> _paI;
    //    private Port<double> _paO;

    //    // filter basic parameters        
    //    private const int _order = 4;
    //    private Iir _iir;

    //    #region Constructors
    //    public Channel()
    //    {
    //        _id     = -1;
    //        _name   = "Channel";
    //        _desc   = "Test Channel (band-limited with AWGN)";
    //        _status = NodeStatus.Stopped;
    //        _grain  = 1;

    //        _sched = new WorkerQueue(_name);
    //        _threads = new Thread[1] { _sched.Thread };
    //        TaskDelegate event1 = new TaskDelegate(Event_XferData);

    //        // create ports     
    //        _paO = new Port<double>("O", IOType.O, _grain, _sched, event1);
    //        _paI = new Port<double>("I", IOType.I, _grain, _sched, event1);

    //        // block IIR            
    //        _iir       = new Iir(_order);
    //        _iir.CoefA = new double[_order] {1.0, 0.0, 0.0, 0.0};
    //        _iir.CoefB = new double[_order] {1.0, 0.0, 0.0, 0.0};
    //        _iir.PortI = new TokenBuffer<double>(_grain);
    //        _iir.PortO = new TokenBuffer<double>(_grain);

    //    }
    //    #endregion

    //    #region Public Methods
    //    public override int Control(NodeExeCtl cmd)
    //    {
    //        switch (cmd)
    //        {
    //            case NodeExeCtl.Start: _status = NodeStatus.Running; _sched.Start(); break;
    //            case NodeExeCtl.Stop:  _status = NodeStatus.Stopped; _sched.Stop();  break;
    //            case NodeExeCtl.Pause: _status = NodeStatus.Paused;  _sched.Abort(); break;
    //        }

    //        return 0;
    //    }
    //    #endregion

    //    #region Private Methods
    //    private void Event_XferData()
    //    {             
    //        if (_status != NodeStatus.Running)
    //            return;

    //        // Check Bound-Buffer Fireable Condition
    //        if ((_paO.TokenCount < _grain) || (_paI.BufferFree < _grain))
    //            return;

    //        _paO.XferData(_iir.PortI.Buffer, 0, _grain);
    //        _iir.Go();
    //        _paI.XferData(_iir.PortI.Buffer, 0, _grain);
    //    }
    //    #endregion
    }
}
